//
// Created by 11510 on 2024/7/18.
//

#ifndef DAY80_DEMO2_CUSTOMBUTTONA_H
#define DAY80_DEMO2_CUSTOMBUTTONA_H

#include <QPushButton>
#include <QMouseEvent>
#include <QDebug>

class CustomButtonA : public QPushButton {
Q_OBJECT
public:
    CustomButtonA(QWidget *parent = nullptr) : QPushButton(parent) {
        setMouseTracking(true);
    }

protected:
    void mousePressEvent(QMouseEvent *e) override {
//        qDebug() << e->type();
        if (e->button() == Qt::LeftButton) {
            m_dragging = true;
        }
    }

    void mouseMoveEvent(QMouseEvent *e) override {
//        qDebug() << e->type();
        if (m_dragging) {
            emit mouseMoved(e->x(), e->y());
        }
    }

    void mouseReleaseEvent(QMouseEvent *e) override {
//        qDebug() << e->type();
        if (e->button() == Qt::LeftButton) {
            m_dragging = false;
        }
    }

signals:

    void mouseMoved(int x, int y);

private:
    bool m_dragging = false;
};


#endif //DAY80_DEMO2_CUSTOMBUTTONA_H
